package com.pms.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.pms.entity.Employee;
import com.pms.util.DBHelp;
import com.pms.util.RowMapper;

public class EmployeeDao {

	private DBHelp<Employee> db=new DBHelp<Employee>();
	
	public Employee findByUsernameAndPassword(String username,String password){
		String sql="SELECT id,username,`password` FROM t_employee WHERE username=? AND `password`=?";
		return db.executeQueryForObject(sql, new EmployeeRowMapper(), username,password);
	}
	
	public Employee findByUserName(String username){
		String sql="SELECT id,username,`password` FROM t_employee WHERE username=?";
		return db.executeQueryForObject(sql, new EmployeeRowMapper(), username);
	}
	
	public class EmployeeRowMapper implements RowMapper<Employee>{

		@Override
		public Employee mapperRow(ResultSet rs) throws SQLException {
			Employee em=new Employee();
			em.setId(rs.getString("id"));
			em.setUsername(rs.getString("username"));
			em.setPassword(rs.getString("password"));
			return em;
		}
		
		
	}
}
